package com.rich.house.controller;

import com.rich.common.dto.house.Result;
import com.rich.common.entity.TbInformation;
import com.rich.house.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @Author: guofeng
 * @Date: 2021/08/16/18:49
 * @Description:
 */
@RestController
@RequestMapping("/information")
public class HouseInformationController {

    @Autowired
    private InformationService informationService;

    /**
     * 返回全部列表
     *
     * @return
     */
    @RequestMapping("/findAll")
    public List<TbInformation> findAll() {
        return informationService.findAll();
    }

    /**
     * 增加
     *
     * @param information
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody TbInformation information) {
        try {
            informationService.add(information);
            return new Result( "增加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result("增加失败");
        }
    }

    /**
     * 修改
     *
     * @param information
     * @return
     */
    @RequestMapping("/update")
    public Result update(@RequestBody TbInformation information) {
        try {
            informationService.update(information);
            return new Result("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result("修改失败");
        }
    }

    /**
     * 获取实体
     *
     * @param id
     * @return
     */
    @RequestMapping("/findOne")
    public TbInformation findOne(Long id) {
        return informationService.findOne(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(Long[] ids) {
        try {
            informationService.delete(ids);
            return new Result("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result("删除失败");
        }
    }

    /**
     * 模糊查询
     * @param
     * @return
     */
    @RequestMapping("/search")
    public List<TbInformation> search(@RequestBody TbInformation information) {
        return informationService.secrch(information);
    }
}